package com.canaan.business.controller.pc.inOutStock;

import com.canaan.business.domain.inOutStock.YardageGoodsRecord;
import com.canaan.business.domain.vo.YardageGoodsLocationVo;
import com.canaan.business.service.inOutStock.IYardageGoodsRecordService;
import com.canaan.common.annotation.Log;
import com.canaan.common.core.controller.BaseController;
import com.canaan.common.core.domain.AjaxResult;
import com.canaan.common.core.page.TableDataInfo;
import com.canaan.common.enums.BusinessType;
import com.canaan.common.utils.poi.ExcelUtil;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 码货记录Controller
 *
 * @author ruoyi
 * @date 2023-02-09
 */
@Api(tags = "码货记录")
@RestController
@RequestMapping("/inOutStock/yardageGoodsRecord")
public class YardageGoodsRecordController extends BaseController {
    @Resource
    private IYardageGoodsRecordService yardageGoodsRecordService;

    /**
     * 查询码货记录列表
     */
    @ApiOperation(value = "查询码货记录列表")
    @GetMapping("/list")
    public TableDataInfo list(YardageGoodsRecord yardageGoodsRecord) {
        startPage();
        List<YardageGoodsRecord> list = yardageGoodsRecordService.selectYardageGoodsRecordList(yardageGoodsRecord);
        return getDataTable(list);
    }

    /**
     * 导出码货记录列表
     */
    @ApiOperation(value = "导出码货记录列表")
    @Log(title = "码货记录", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, YardageGoodsRecord yardageGoodsRecord) {
        List<YardageGoodsRecord> list = yardageGoodsRecordService.selectYardageGoodsRecordList(yardageGoodsRecord);
        ExcelUtil<YardageGoodsRecord> util = new ExcelUtil<YardageGoodsRecord>(YardageGoodsRecord.class);
        util.exportExcel(response, list, "码货记录数据");
    }

    /**
     * 获取码货库位列表
     */
    @ApiOperation(value = "获取码货库位列表")
    @GetMapping(value = "/findYardLocation/{inOrderDetailId}")
    public List<YardageGoodsLocationVo> findYardLocation(@PathVariable("inOrderDetailId") Long inOrderDetailId) {
        return yardageGoodsRecordService.selectLocationByInOrderId(inOrderDetailId);
    }
    /**
     * 获取码货记录详细信息
     */
    @ApiOperation(value = "获取码货记录详细信息")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id) {
        return success(yardageGoodsRecordService.selectYardageGoodsRecordById(id));
    }

    /**
     * 新增码货记录
     */
    @ApiOperation(value = "新增码货记录")
    @Log(title = "码货记录", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody YardageGoodsRecord yardageGoodsRecord) {
        return toAjax(yardageGoodsRecordService.insertYardageGoodsRecord(yardageGoodsRecord));
    }

    /**
     * 修改码货记录
     */
    @ApiOperation(value = "修改码货记录")
    @Log(title = "码货记录", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody YardageGoodsRecord yardageGoodsRecord) {
        return toAjax(yardageGoodsRecordService.updateYardageGoodsRecord(yardageGoodsRecord));
    }

    /**
     * 删除码货记录
     */
    @ApiOperation(value = "删除码货记录")
    @Log(title = "码货记录", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids) {
        return toAjax(yardageGoodsRecordService.deleteYardageGoodsRecordByIds(ids));
    }
}
